package com.cloud.bc.service.impl;

import com.cloud.bc.model.entity.BcMessageSendRecord;
import com.cloud.bc.mapper.BcMessageSendRecordMapper;
import com.cloud.bc.service.BcMessageSendRecordService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 信息发送记录
 *
 * @author douhaichao code generator
 * @date 2021-01-31 09:19:05
 */
@Service
@AllArgsConstructor
public class BcMessageSendRecordServiceImpl extends ServiceImpl<BcMessageSendRecordMapper, BcMessageSendRecord> implements BcMessageSendRecordService {

    /**
   * 根据对象属性查找满足条件的第一条数据     *      * @return
   */
    @Override
    public BcMessageSendRecord selectOne(BcMessageSendRecord req) {
        QueryWrapper queryWrapper = new QueryWrapper<BcMessageSendRecord>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<BcMessageSendRecord> selectAll(BcMessageSendRecord req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<BcMessageSendRecord> selectPage(Page page, BcMessageSendRecord req) {
        IPage<BcMessageSendRecord> list = baseMapper.selectPage(
                page,
                new QueryWrapper<BcMessageSendRecord>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<BcMessageSendRecord> selectPageByLike(Page page, BcMessageSendRecord req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        
                                        if (null !=req.getId()) {
                    queryWrapper.eq("id" , req.getId());
                }
                    
                            if (!StrUtil.isEmpty(req.getSendNo())) {
                    queryWrapper.like("send_no" , req.getSendNo());
                }
                                
                            if (!StrUtil.isEmpty(req.getSendContent())) {
                    queryWrapper.like("send_content" , req.getSendContent());
                }
                                
                                        if (null !=req.getSendType()) {
                    queryWrapper.eq("send_type" , req.getSendType());
                }
                    
                                        if (null !=req.getCreateTime()) {
                    queryWrapper.eq("create_time" , req.getCreateTime());
                }
                            IPage<BcMessageSendRecord> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(BcMessageSendRecord req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
